package net.xdclass.controller;

import io.swagger.v3.oas.annotations.Operation;
import net.xdclass.controller.req.RecycleDelReq;
import net.xdclass.controller.req.RecycleRestoreReq;
import net.xdclass.dto.AccountFileDTO;
import net.xdclass.interceptor.LoginInterceptor;
import net.xdclass.service.RecycleService;
import net.xdclass.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 姜阿木
 * @date 2025/7/23 16:38
 */
@RestController
@RequestMapping("/api/recycle/v1")
public class RecycleController {

    @Autowired
    private RecycleService recycleService;
    /**
     * 获取回收站列表
     *
     * @return
     */
    @GetMapping("list")
    @Operation(summary = "获取回收站列表", description = "获取回收站列表")
    public JsonData list() {
        Long accountId = LoginInterceptor.threadLocal.get().getId();
        List<AccountFileDTO> list = recycleService.listRecycleFiles(accountId);
        return JsonData.buildSuccess(list);
    }

    /**
     * 删除回收站文件，彻底删除
     *
     * @param req
     * @return
     */
    @PostMapping("delete")
    @Operation(summary = "删除回收站文件", description = "删除回收站文件")
    public JsonData delete(@RequestBody RecycleDelReq req) {
        req.setAccountId(LoginInterceptor.threadLocal.get().getId());
        recycleService.delete(req);
        return JsonData.buildSuccess();
    }

    /**
     * 还原回收站文件
     *
     * @param req
     * @return
     */
    @PostMapping("restore")
    @Operation(summary = "还原回收站文件", description = "还原回收站文件")
    public JsonData restore(@RequestBody RecycleRestoreReq req) {
        req.setAccountId(LoginInterceptor.threadLocal.get().getId());
        recycleService.restore(req);
        return JsonData.buildSuccess();
    }
}








